package com.lm.memcached.controller;

import com.lm.memcached.utils.MemcachedUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cache")
public class CacheController {

    private final MemcachedUtils memcachedUtils;

    public CacheController(MemcachedUtils memcachedUtils) {
        this.memcachedUtils = memcachedUtils;
    }

    @PostMapping("/set")
    public String set(@RequestParam String key, @RequestParam String value) {
        memcachedUtils.set(key, value);
        return "✅ 缓存设置成功: " + key;
    }

    @GetMapping("/get")
    public Object get(@RequestParam String key) {
        return memcachedUtils.get(key);
    }

    @DeleteMapping("/delete")
    public String delete(@RequestParam String key) {
        memcachedUtils.delete(key);
        return "🗑️ 已删除缓存: " + key;
    }
}